/*
 * Copyright 2007-208 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
class CASTagLibTest extends GroovyTestCase {
 
	void testCode3() {
		println CASTagLib.format('3', 0, 1234567)
	}
	void testDates() {
		assertEquals ('1/23/56', CASTagLib.format('Y', 0, 12356))
		assertEquals ('1/23/1956', CASTagLib.format('Y', 0, 1231956))
		assertEquals ('12/23/1956', CASTagLib.format('Y', 0, 12231956))
	}
	/*
	test against DDS man page 
	http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzakc/rzakcmstdfedtcd.htm
	put results in lists
	then assert the results against static arrays from the DDS man page
	*/
	void testDDSManPage() {
		def codes = ['1', '2', '3', '4', 'A', 'B', 'C', 'D', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'W', 'Y', 'Z']
		def data = [12345.67, 1234567, -0.125, -125, 0, 0] 
		def dataDecimals = [2, 0, 3, 0, 2, 0] 
		println "Unedited\t12345.67\t1234567\t\t.125-\t125-\tblank\tblank"
		def actual = []
		codes.each {code ->
			def actualElem  = [code]
			data.eachWithIndex {value, i ->
				actualElem[i+1] = CASTagLib.format(code, dataDecimals[i], value)
			}
			actual << actualElem 
		}
		def expected = [
			['1', '12,345.67', '1,234,567', '.125', '125', '.00', '0'],
			['2', '12,345.67', '1,234,567', '.125', '125', '',''],
			['3', '12345.67', '1234567', '.125', '125', '.00', '0'],
			['4', '12345.67', '1234567', '.125', '125', '',''],
			['A', '12,345.67', '1,234,567', '.125CR', '125CR', '.00', '0'],
			['B', '12,345.67', '1,234,567', '.125CR', '125CR', '',''],
			['C', '12345.67', '1234567', '.125CR', '125CR', '.00', '0'],
			['D', '12345.67', '1234567', '.125CR', '125CR', '',''],
			['J', '12,345.67', '1,234,567', '.125-', '125-', '.00', '0'],
			['K', '12,345.67', '1,234,567', '.125-', '125-', '',''],
			['L', '12345.67', '1234567', '.125-', '125-', '.00', '0'],
			['M', '12345.67', '1234567', '.125-', '125-', '',''],
			['N', '12,345.67', '1,234,567', '-.125', '-125', '.00', '0'],
			['O', '12,345.67', '1,234,567', '-.125', '-125', '',''],
			['P', '12345.67', '1234567', '-.125', '-125', '.00', '0'],
			['Q', '12345.67', '1234567', '-.125', '-125', '', ''],
			['W', '1234/567', '1234/567', '0/125', '0/125', '0/000', '0/000'],
			//['Y', '123/45/67', '123/45/67', '0/01/25', '0/01/25', '0/00/00', '0/00/00'], I don't like this as it doesn't support century
			['Y', '1/23/4567', '1/23/4567', '0/01/25', '0/01/25', '0/00/00', '0/00/00'],
			//['Z', '1234567', '1234567', '125', '125', '', ''] I don't like this as it doesn't show the decimal place
			['Z', '12345.67', '1234567', '.125', '125', '', '']
		]
		//println "Actuals:"; actual.each{println it }
		//println "Expected:"; expected.each{println it }
		actual.eachWithIndex {line, i ->
			assertEquals (expected[i], actual[i])
		}
	}

}
